package com.napenalki.toto.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Event {

    private int id;
    private Date date;
    private boolean isLocked = false;
    private String result;
    private List<Prediction> predictions;
    
    public Event() {
    }
    
    public Event(Date date, boolean isLocked, String result) {
        this.date = date;
        this.isLocked = isLocked;
        this.result = result;
        this.predictions = new ArrayList<Prediction>();
    }

    public Event(int id, Date date, boolean isLocked, String result) {
        this.id = id;
        this.date = date;
        this.isLocked = isLocked;
        this.result = result;
        this.predictions = new ArrayList<Prediction>();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    @Column(name = "ID")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "EVENT_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Column(name = "LOCKED")
    public boolean isLocked() {
        return isLocked;
    }

    public void setLocked(boolean isLocked) {
        this.isLocked = isLocked;
    }

    @Column(name = "RESULT")
    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    @OneToMany(mappedBy = "event", cascade = CascadeType.ALL)
    public List<Prediction> getPredictions() {
        return predictions;
    }

    public void setPredictions(List<Prediction> predictions) {
        this.predictions = predictions;
    }
    
}
